<template>
  <div>
    <el-container style="padding-left:5px">
      <el-main>
        <KendoGridCmpt
          :ref="'ReqTestGrid'"
          :table-grid-option="tableGridOption"
          :table-grid-data-source-option="tableGridDataSourceOption"
          @persistSelection="selectDataItems"
        />
      </el-main>
    </el-container>
  </div>

</template>

<script>
  export default {
    name: 'PrjReqTaskManage',
    data() {
      return {
        // maintain 需求信息数据列表
        tableGridOption: {
          ref: 'ReqTestCaseGrid',
          dataSourceRef: 'reqTestCaseDataSource',
          remoteData: true,
          sortable: true,
          reorderable: true,
          resizable: true,
          pageable: true,
          selectSingle: true,
          selectMultiple: false,
          toolbar: ['excel'],
          excel: {
            fileName: '需求信息数据列表',
            allPages: true,
            filterable: true
          },
          columns: [
            {
              field: 'reqNo',
              title: '需求名称',
              width: 200,
              dictData: 'TASK_REQ_NO_CD'
            },
            {
              field: 'reqReceiveDt',
              title: '需求接收时间',
              width: 100
            },

            {
              field: 'devInCharge',
              title: '开发负责人',
              width: 120,
              dictData: 'MEMBER_NO_CD'
            },
            {
              field: 'reqInCharge',
              title: '需求负责人',
              width: 120
            },
            {
              field: 'reqTaskExecutor',
              title: '需求任务执行人',
              width: 120
            },
            {
              field: 'testCaseGategory',
              title: '测试案例分类',
              width: 120,
              dictData: 'TEST_CASE_GATEGORY_CD'
            },
            {
              field: 'testCaseName',
              title: '测试案例',
              width: 160
            },
            {
              field: 'testStartDt',
              title: '测试开始日期',
              width: 120
            },
            {
              field: 'testEndDt',
              title: '测试结束日期',
              width: 120
            },
            {
              field: 'currentGeneration',
              title: '当前测试阶段',
              width: 120,
              dictData: 'CURRENT_TEST_GENERATION_CD'
            },
            {
              field: 'caseTestScheduling',
              title: '当前案例测试进度',
              width: 80,
              format: '{0:p2}'
            },
            {
              field: 'whetherCmpl',
              title: '是否完成',
              width: 120,
              dictData: 'WHETHER_CMPL_CD'
            }
          ]
        },
        tableGridDataSourceOption: {
          ref: 'reqTestCaseDataSource',
          type: 'json',
          pageSize: 10,
          transportReadUrl: '/service/prjMng/testCaseMng/findReqMntTestCasePage',
          serverPaging: true,
          batch: true,
          dict: ['CURRENT_TEST_GENERATION_CD', 'WHETHER_CMPL_CD'],
          remoteTransData: {
            MEMBER_NO_CD: {
              transportName: 'prjMemberMngServiceImpl',
              transportMethod: 'prjMemberTransDict',
              transportParam: {}
            },
            TEST_CASE_GATEGORY_CD: {
              transportName: 'reqmntTccServiceImpl',
              transportMethod: 'findReqmntTccTransDict',
              transportParam: {
                reqNo: this.$attrs.data.param.reqNo
              }
            },
            TASK_REQ_NO_CD: {
              transportName: 'reqmntTaskServiceImpl',
              transportMethod: 'reqTaskNoTransDict',
              transportParam: {}
            }
          },
          params: {},
          schema: {
            model: {
              id: 'id',
              fields: {
                reqNo: { editable: false, type: 'string' },
                devInCharge: { editable: false, type: 'string' },
                reqInCharge: { editable: false, type: 'string' },
                reqTaskExecutor: { editable: false, type: 'string' },
                testStartDt: { editable: true, type: 'string', format: 'yyyy-MM-dd' },
                testEndDt: { editable: true, type: 'string', format: 'yyyy-MM-dd' },
                caseTestScheduling: { editable: true, type: 'number' }

              }
            },
            data: function(response) {
              return response.data.list
            },
            total: function(response) {
              return response.data.total
            }
          },
          parameterMap: this.parameterMap
        },
        selectData: []
      }
    },
    mounted() {

    },
    methods: {
      isEmpty(str) {
        if (str === null || typeof str === 'undefined' || str === '') {
          return true
        }
        return false
      },
      /* grid*/
      parameterMap(options, operation) {
        const { reqNo } = this.$attrs.data.param
        if (operation !== 'read' && options.models) {
          const parameterMap = {}
          const models = options.models
          models.forEach(element => {
            element.testStartDt = this.isEmpty(element.testStartDt) ? '' : this.dateFormat(new Date(element.testStartDt), 'yyyy-MM-dd')
            element.testEndDt = this.isEmpty(element.testEndDt) ? '' : this.dateFormat(new Date(element.testEndDt), 'yyyy-MM-dd')
          })
          parameterMap.models = options.models
          return {
            // eslint-disable-next-line no-undef
            parameterMap: kendo.stringify(parameterMap)
          }
        } else {
          let parameterMap = {}
          parameterMap.pageNum = options.page
          parameterMap.pageSize = options.pageSize
          parameterMap.reqNo = reqNo
          parameterMap = Object.assign(parameterMap, { })
          // eslint-disable-next-line no-undef
          return kendo.stringify(parameterMap)
        }
      },
      selectDataItems(res) {
        this.selectData = res
      }
    }
  }
</script>

<style>

</style>
